/*
 * @Descripttion: 路由定义
 * @Author: xiej
 * @Date: 2020-05-14 16:56:41
 * @LastEditors: xiej
 * @LastEditTime: 2021-03-23 10:48:52
 */
import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/redirect/:path*',
    component: resolve => require(['@/views/redirect/index'], resolve),
    hidden: true
  },
  {
    path: '/404',
    component: resolve => require(['@/views/error-page/404'], resolve),
    hidden: true
  },
  {
    path: '/401',
    component: resolve => require(['@/views/error-page/401'], resolve),
    hidden: true
  },
  {
    path: '/sysm',
    hidden: true,
    component: resolve => require(['@/views/layout'], resolve),
    hidden: true
  },
  {
    path: '/',
    component: resolve => require(['@/views/layout'], resolve),
    redirect: '/index',
    hidden: true,
    children: [
      {
        path: 'index',
        component: resolve => require(['@/views/dsc'], resolve),
        name: 'Welcome',
        meta: { title: '首页', affix: true }
      },
      {
        path: 'user',
        component: resolve => require(['@/views/dsc/sysm/user'], resolve),
        name: 'Welcomea',
        meta: { title: '用户管理', affix: false }
      },
      {
        path: 'user/group',
        component: resolve => require(['@/views/dsc/sysm/user/group'], resolve),
        name: 'Welcomeb',
        meta: { title: '用户组管理', affix: false }
      },
      {
        path: 'platform',
        component: resolve => require(['@/views/dsc/sysm/platform'], resolve),
        name: 'Welcomec',
        meta: { title: '平台管理', affix: false }
      },
      {
        path: 'platform/modular',
        component: resolve => require(['@/views/dsc/sysm/platform/modular'], resolve),
        name: 'Welcomed',
        meta: { title: '模块管理', affix: false }
      },
      {
        path: 'platform/function',
        component: resolve => require(['@/views/dsc/sysm/platform/function'], resolve),
        name: 'Welcomee',
        meta: { title: '功能管理', affix: false }
      },
      {
        path: 'organization/company',
        component: resolve => require(['@/views/dsc/sysm/organization/company'], resolve),
        name: 'company',
        meta: { title: '公司管理', affix: false }
      },
      {
        path: 'organization/department',
        component: resolve => require(['@/views/dsc/sysm/organization/department'], resolve),
        name: 'department',
        meta: { title: '部门管理', affix: false }
      },
      {
        path: 'organization/staff',
        component: resolve => require(['@/views/dsc/sysm/organization/staff'], resolve),
        name: 'staff',
        meta: { title: '员工管理', affix: false }
      },
      {
        path: 'and/staff',
        component: resolve => require(['@/views/dsc/sysm/and/staff'], resolve),
        name: 'staffa',
        meta: { title: '员工字典', affix: false }
      },
      {
        path: 'and/project',
        component: resolve => require(['@/views/dsc/sysm/and/project'], resolve),
        name: 'project',
        meta: { title: '项目字典', affix: false }
      },
      {
        path: 'and/purchase',
        component: resolve => require(['@/views/dsc/sysm/and/purchase'], resolve),
        name: 'purchase',
        meta: { title: '采购字典', affix: false }
      },
      {
        path: 'notice',
        component: resolve => require(['@/views/dsc/sysm/notice'], resolve),
        name: 'purchase',
        meta: { title: '公告管理', affix: false }
      },
      {
        path: 'backups/system',
        component: resolve => require(['@/views/dsc/sysm/backups/system'], resolve),
        name: 'purchase',
        meta: { title: '系统备份管理', affix: false }
      },
      {
        path: 'backups',
        component: resolve => require(['@/views/dsc/sysm/backups/index'], resolve),
        name: 'purchase',
        meta: { title: '备份记录管理', affix: false }
      },
      {
        path: 'journal/operation',
        component: resolve => require(['@/views/dsc/sysm/journal/operation'], resolve),
        name: 'purchase',
        meta: { title: '操作日志', affix: false }
      },
      {
        path: 'journal/error',
        component: resolve => require(['@/views/dsc/sysm/journal/error'], resolve),
        name: 'purchase',
        meta: { title: '错误日志', affix: false }
      },
      {
        path: 'journal/sign',
        component: resolve => require(['@/views/dsc/sysm/journal/sign'], resolve),
        name: 'purchase',
        meta: { title: '登录日志', affix: false }
      },
			{
        path: 'stration/design',
        component: resolve => require(['@/views/sysm/stration/design'], resolve),
        name: 'purchase',
        meta: { title: '流程设计管理', affix: false }
      },
      {
        path: 'stration/entrust',
        component: resolve => require(['@/views/sysm/stration/entrust'], resolve),
        name: 'purchase',
        meta: { title: '委托人员管理', affix: false }
      },
			{
			  path: 'stration/autograph',
			  component: resolve => require(['@/views/sysm/stration/autograph'], resolve),
			  name: 'purchase',
			  meta: { title: '电子签名管理', affix: false }
			},
			{
			  path: 'stration/company',
			  component: resolve => require(['@/views/sysm/stration/company'], resolve),
			  name: 'purchase',
			  meta: { title: '公司印章管理', affix: false }
			},
			{
			  path: 'stration/type',
			  component: resolve => require(['@/views/sysm/stration/type'], resolve),
			  name: 'purchase',
			  meta: { title: '流程分类管理', affix: false }
			}
      // {
      //   path: '/user/group',//用户组管理
      //   hidden: true,
      //   component: resolve => require(['@/views/dsc/sysm/user/group'], resolve)
      // }
    ]
  }
  // {
  //   path: '/fbms',
  //   hidden: true,
  //   component: resolve => require(['@/views/dsc/sysm/fbms'], resolve)
  // }
  // {
  //   path: '/user/group',//用户组管理
  //   hidden: true,
  //   component: resolve => require(['@/views/dsc/sysm/user/group'], resolve)
  // }
]

if (!window.__POWERED_BY_QIANKUN__) {
  constantRoutes.push(...[
    // {
    //   path: '/',
    //   component: resolve => require(['@/views/layout'], resolve),
    //   redirect: '/index',
    //   hidden: true,
    //   children: [
    //     {
    //       path: 'index',
    //       component: resolve => require(['@/views/dsc'], resolve),
    //       name: 'Welcome',
    //       meta: { title: '首页', affix: true }
    //     },
    //     {
    //       path: 'user',
    //       component: resolve => require(['@/views/dsc/sysm/user'], resolve),
    //       name: 'Welcomea',
    //       meta: { title: '用户管理', affix: false }
    //     },
    //     {
    //       path: 'user/group',
    //       component: resolve => require(['@/views/dsc/sysm/user/group'], resolve),
    //       name: 'Welcomeb',
    //       meta: { title: '用户组管理', affix: false }
    //     },
    //     {
    //       path: 'platform',
    //       component: resolve => require(['@/views/dsc/sysm/platform'], resolve),
    //       name: 'Welcomec',
    //       meta: { title: '平台管理', affix: false }
    //     },
    //     {
    //       path: 'platform/modular',
    //       component: resolve => require(['@/views/dsc/sysm/platform/modular'], resolve),
    //       name: 'Welcomed',
    //       meta: { title: '模块管理', affix: false }
    //     },
    //     {
    //       path: 'platform/function',
    //       component: resolve => require(['@/views/dsc/sysm/platform/function'], resolve),
    //       name: 'Welcomee',
    //       meta: { title: '功能管理', affix: false }
    //     },
    //     {
    //       path: 'organization/company',
    //       component: resolve => require(['@/views/dsc/sysm/organization/company'], resolve),
    //       name: 'company',
    //       meta: { title: '公司管理', affix: false }
    //     },
    //     {
    //       path: 'organization/department',
    //       component: resolve => require(['@/views/dsc/sysm/organization/department'], resolve),
    //       name: 'department',
    //       meta: { title: '部门管理', affix: false }
    //     },
    //     {
    //       path: 'organization/staff',
    //       component: resolve => require(['@/views/dsc/sysm/organization/staff'], resolve),
    //       name: 'staff',
    //       meta: { title: '员工管理', affix: false }
    //     },
    //     {
    //       path: 'and/staff',
    //       component: resolve => require(['@/views/dsc/sysm/and/staff'], resolve),
    //       name: 'staffa',
    //       meta: { title: '员工字典', affix: false }
    //     },
    //     {
    //       path: 'and/project',
    //       component: resolve => require(['@/views/dsc/sysm/and/project'], resolve),
    //       name: 'project',
    //       meta: { title: '项目字典', affix: false }
    //     },
    //     {
    //       path: 'and/purchase',
    //       component: resolve => require(['@/views/dsc/sysm/and/purchase'], resolve),
    //       name: 'purchase',
    //       meta: { title: '采购字典', affix: false }
    //     },
    //     {
    //       path: 'notice',
    //       component: resolve => require(['@/views/dsc/sysm/notice'], resolve),
    //       name: 'purchase',
    //       meta: { title: '公告管理', affix: false }
    //     },
    //     {
    //       path: 'backups/system',
    //       component: resolve => require(['@/views/dsc/sysm/backups/system'], resolve),
    //       name: 'purchase',
    //       meta: { title: '系统备份管理', affix: false }
    //     },
    //     {
    //       path: 'backups',
    //       component: resolve => require(['@/views/dsc/sysm/backups/index'], resolve),
    //       name: 'purchase',
    //       meta: { title: '备份记录管理', affix: false }
    //     },
    //     {
    //       path: 'journal/operation',
    //       component: resolve => require(['@/views/dsc/sysm/journal/operation'], resolve),
    //       name: 'purchase',
    //       meta: { title: '操作日志', affix: false }
    //     },
    //     {
    //       path: 'journal/error',
    //       component: resolve => require(['@/views/dsc/sysm/journal/error'], resolve),
    //       name: 'purchase',
    //       meta: { title: '错误日志', affix: false }
    //     },
    //     {
    //       path: 'journal/sign',
    //       component: resolve => require(['@/views/dsc/sysm/journal/sign'], resolve),
    //       name: 'purchase',
    //       meta: { title: '登录日志', affix: false }
    //     }
    //     // {
    //     //   path: '/user/group',//用户组管理
    //     //   hidden: true,
    //     //   component: resolve => require(['@/views/dsc/sysm/user/group'], resolve)
    //     // }
    //   ]
    // },
    {
      path: '/login',
      hidden: true,
      component: resolve => require(['@/views/login/index'], resolve)
    // component: resolve => require(['@/views/dsc/sysm/notice'], resolve)
    },
    {
      path: '/sysm',
      hidden: true,
      component: resolve => require(['@/views/dsc/sysm/index'], resolve)
    },
    {
      path: '/menu',
      hidden: true,
      component: resolve => require(['@/views/dsc/system/menu'], resolve)
    }
  ])
}

/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */
export const asyncRoutes = []
export const createRouter = () => new Router({
  // base: window.__POWERED_BY_QIANKUN__ ? '/sysm' : '/',
  mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
